﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Services
{
	using System.Collections.Generic;
	using Falcon.Core.Domain;
	using Falcon.Core.Domain.Repositories;
	using Falcon.Core.Domain.Services;
	using Falcon.Core.Domain.Values;

	public class LanguageService : ILanguageService
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="LanguageService"/> class.
		/// </summary>
		/// <param name="languageRepository">The language repository.</param>
		public LanguageService(ILanguageRepository languageRepository)
		{
			this.LanguageRepository = languageRepository;
		}

		/// <summary>
		/// Gets or sets the language repository.
		/// </summary>
		/// <value>The language repository.</value>
		public ILanguageRepository LanguageRepository
		{
			get; 
			private set;
		}

		/// <summary>
		/// Gets the language by id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns></returns>
		public Language GetById(int id)
		{
			return this.LanguageRepository.GetById(id);
		}

		/// <summary>
		/// Get all the languages.
		/// </summary>
		/// <returns></returns>
		public IList<Language> GetAll()
		{
			return this.LanguageRepository.GetAll();
		}

		/// <summary>
		/// Creates the language.
		/// </summary>
		/// <returns></returns>
		public Language Create()
		{
			return new Language();
		}

		/// <summary>
		/// Inserts the language into the storage.
		/// </summary>
		/// <param name="language">The <see cref="Language"/>.</param>
		public void Insert(Language language)
		{
			this.LanguageRepository.Insert(language);
		}

		/// <summary>
		/// Inserts the specified language.
		/// </summary>
		/// <param name="language">The language.</param>
		/// <param name="value">The value.</param>
		public void Insert(Language language, LanguageCreate value)
		{
			value.Validate();

			language.Title = value.Title;
			language.Culture = value.Culture;

			this.Insert(language);
		}

		/// <summary>
		/// Updates the specified language.
		/// </summary>
		/// <param name="language">The <see cref="Language"/>.</param>
		public void Update(Language language)
		{
			this.LanguageRepository.Update(language);
		}

		/// <summary>
		/// Updates the specified language.
		/// </summary>
		/// <param name="language">The language.</param>
		/// <param name="value">The value.</param>
		public void Update(Language language, LanguageUpdate value)
		{
			value.Validate();

			language.Title = value.Title;
			language.Culture = value.Culture;

			this.Update(language);
		}

		/// <summary>
		/// Deletes the specified language.
		/// </summary>
		/// <param name="language">The <see cref="Language"/>.</param>
		public void Delete(Language language)
		{
			this.LanguageRepository.Delete(language);
		}
	}
}